﻿using System;
using Microsoft.Practices.Unity;

namespace Unify.Tests
{
    /// <summary>
    /// Durée de vie d'une session http
    /// </summary>
    public class UnityCustomLifetimeManager : LifetimeManager
    {
        /// <summary>
        /// Garde l'id de la session http
        /// </summary>
        private readonly string _sessionKey;

        /// <summary>
        /// Ctor with sessionID injected by construction
        /// </summary>
        /// <param name="sessionKey"></param>
        public UnityCustomLifetimeManager(string sessionKey)
        {
            this._sessionKey = sessionKey;
        }

        /// <summary>
        /// Empty Ctor
        /// </summary>
        public UnityCustomLifetimeManager()
        {
            this._sessionKey = Guid.NewGuid().ToString();
        }

        #region LifetimeManager overrided impl.

        private object data = null;

        public override object GetValue()
        {
            return data;
        }

        public override void RemoveValue()
        {
            data = null;
        }

        public override void SetValue(object newValue)
        {
            data = newValue;
        }

        #endregion
    }
}